

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AjaxServlet
 */
public class AjaxServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AjaxServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String user_name = request.getParameter("UserName");
	    if(user_name.equalsIgnoreCase(""))
	    	{System.out.println("space");
	     }
		String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
		String url_base="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=";
		String db_name="XUANKE";
		String name="sa";
		String password="";
		
		DataBase database = new DataBase(driver,url_base,db_name,name,password);
		
		String SQL="select UserName from Users where UserName like '"+user_name+"%' order by UserName";  
		String result = database.excuteQuery(SQL);   
		
        PrintWriter out = response.getWriter();  
        out.print(result); 
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 
	}

}
